package cj.web.utils;

public class StandardResponse {
	private int code;
	private String msg;
	private Object data;
	private static StandardResponse instance;
	private static Object lock = new Object();

	public static StandardResponse getStandardResponse() {
		if (instance == null) {
			synchronized (lock) {
				if (instance == null) {
					instance = new StandardResponse();
				}
			}
		}
		return instance;
	}
	
	/**
	 * 标准返回值
	 * 
	 * @Function: response	
	 * @Description:
	 * @Calls:		
	 * @Called By:
	 * @Input: 
	 * @output @param responseCode 标准返回
	 * @output @param data         自定义返回数据
	 * @output @return				
	 * @Return:	StandardResponse	
	 *
	 */
	public static StandardResponse response(ResponseCode responseCode,Object data){
		StandardResponse standardResponse = getStandardResponse(); 
		standardResponse.setCode(responseCode.code);
		standardResponse.setMsg(responseCode.msg);
		if(null != data){
			standardResponse.setData(data);
		}else{
			standardResponse.setData(responseCode.getData());
		}
		return standardResponse;
	}
	
	public enum ResponseCode {
		BT_PARAM_ERROR(-1, "error","抱歉,参数异常"),
		BT_NOT_ADD_VOTE(-2, "error","抱歉,官方还没有发起投票!"),
		BT_WECHAT_LOGIN_ERROR(-3, "error","抱歉,微信登陆失败!"),
		BT_QUERY_SONG_FIELD(-4, "error","抱歉,查询歌曲失败 !"),
		BT_VOTE_BEFORE(-5, "error","抱歉,您已经投过票了!"),
		SUCCESS(0,"success",null);

		private final int code;
		private final String msg;
		private final String data;
		private ResponseCode(int code, String msg, String data) {
			this.code = code;
			this.msg = msg;
			this.data = data;
		}
		public int getCode() {
			return code;
		}
		public String getMsg() {
			return msg;
		}
		public String getData() {
			return data;
		}
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}
}
